package rs.udd.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import rs.udd.model.Category;

public interface CategoryRepository extends JpaRepository<Category, Long> {

	public Category findCategoryByName(String name);

	@Query("SELECT c FROM Category c WHERE c.name LIKE %:name%")
	public List<Category> findCategoryByNameLike(@Param("name") String name);
	
	// @Query("SELECT c FROM Category c JOIN c.hiddenByAgents a WHERE a = :agent")
	// @Query("SELECT c FROM Category c LEFT JOIN c.hiddenByAgents a WHERE a != :agent")
	// FIXME categories not hidden by agent
	// @Query("SELECT c FROM Category c JOIN c.hiddenByAgents a WHERE :agent NOT IN a")
	// public List<Category> findAllCategoriesShownByAgent(@Param("agent") Agent agent);
	@Query("SELECT c FROM Category c WHERE :agent NOT IN (select id from c.hiddenByAgents)")
	public List<Category> findAllCategoriesShownByAgent(@Param("agent") Long agent);

}
